package com.ktjy.service.impl;

import com.ktjy.dto.LoginUser;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service("ss")
public class PermssionService {
    public boolean hasPerm(String perm){
        if(perm==null || "".equals(perm)){
            return false;
        }
        //获取当前登录用户
        LoginUser loginUser= (LoginUser)
               SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Set<String> perms = loginUser.getPerms();

        //判断传过来的权限编码是否在set集合存在
        return perms.contains("*:*:*") || perms.contains(perm);
    }
}
